#include "stdafx.h"
#include "CppUnitTest.h"
#include "../Tenta-v3-3,4/unordered_list.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

namespace UnitTestTentaV3
{		
	TEST_CLASS(UnitTestTentaV3)
	{
	public:
		
		TEST_METHOD(TestTentaV3Empty)
		{
			unordered_list ul;
			Assert::AreEqual(true, ul.empty());
		}

		TEST_METHOD(TestTentaV3FreeListSize)
		{
			unordered_list ul;
			Assert::AreEqual(0, ul.free_list_size());
			unordered_list ul2(5);
			Assert::AreEqual(true, ul2.empty());
			Assert::AreEqual(5, ul2.free_list_size());
		}

		TEST_METHOD(TestTentaV3Add)
		{
			unordered_list ul(1);
			Assert::AreEqual(true, ul.empty());
			Assert::AreEqual(1, ul.free_list_size());
			ul.add("a");
			Assert::AreEqual(false, ul.empty());
			Assert::AreEqual(0, ul.free_list_size());
			ul.add("b");
			Assert::AreEqual(false, ul.empty());
			Assert::AreEqual(0, ul.free_list_size());
		}

		TEST_METHOD(TestTentaV3Print)
		{
			unordered_list ul(2);
			ul.add("a");
			ul.add("b");
			ul.add("c");
			string s = "c,b,a";
			Assert::AreEqual(s, ul.print());
		}

		TEST_METHOD(TestTentaV3CopyContructor)
		{
			unordered_list ul1(4);
			ul1.add("a");
			ul1.add("b");
			unordered_list ul2(ul1);
			Assert::AreEqual(ul1.empty(), ul2.empty());
			Assert::AreEqual(ul1.free_list_size(), ul2.free_list_size());
			Assert::AreEqual(ul1.print(), ul2.print());
		}

		TEST_METHOD(TestTentaV3CopyAssignment)
		{
			unordered_list ul1(4);
			ul1.add("a");
			ul1.add("b");
			unordered_list ul2(4);
			ul2.add("c");
			ul2.add("d");
			ul2 = ul1;
			Assert::AreEqual(ul1.empty(), ul2.empty());
			Assert::AreEqual(ul1.free_list_size(), ul2.free_list_size());
			Assert::AreEqual(ul1.print(), ul2.print());
		}

		TEST_METHOD(TestTentaV3Clear)
		{
			unordered_list ul(4);
			ul.add("a");
			ul.add("b");
			ul.add("c");
			ul.add("d");
			ul.add("e");
			Assert::AreEqual(0, ul.free_list_size());
			ul.clear();
			Assert::AreEqual(true, ul.empty());
			Assert::AreEqual(5, ul.free_list_size());
		}

		TEST_METHOD(TestTentaV3Remove)
		{
			unordered_list ul(4);
			ul.add("a");
			ul.add("b");
			ul.add("c");
			ul.add("d");
			ul.add("e");
			ul.remove("d");
			string s = "e,c,b,a";
			Assert::AreEqual(s, ul.print());
			Assert::AreEqual(1, ul.free_list_size());
			ul.remove("a");
			s = "e,c,b";
			Assert::AreEqual(s, ul.print());
			Assert::AreEqual(2, ul.free_list_size());
			ul.remove("e");
			s = "c,b";
			Assert::AreEqual(s, ul.print());
			Assert::AreEqual(3, ul.free_list_size());
		}

		TEST_METHOD(TestTentaV3Search)
		{
			unordered_list ul(4);
			ul.add("a");
			ul.add("b");
			ul.add("c");
			ul.add("d");
			ul.add("e");
			string s = "b";
			Assert::AreEqual(s, ul.search("b")->data);
			s = "b,e,d,c,a";
			Assert::AreEqual(s, ul.print());
			s = "b";
			Assert::AreEqual(s, ul.search("b")->data);
			s = "b,e,d,c,a";
			Assert::AreEqual(s, ul.print());
			s = "a";
			Assert::AreEqual(s, ul.search("a")->data);
			s = "a,b,e,d,c";
			Assert::AreEqual(s, ul.print());
			s = "e";
			Assert::AreEqual(s, ul.search("e")->data);
			s = "e,a,b,d,c";
			Assert::AreEqual(s, ul.print());
		}

		TEST_METHOD(TestTentaV3Iterator)
		{
			unordered_list ul(4);
			ul.add("a");
			ul.add("b");
			ul.add("c");
			ul.add("d");
			ul.add("e");
			char c = 'e';
			for (auto &s : ul)
			{
				Assert::AreEqual(c, s.data[0]);
				c--;
			}
		}
	};
}